<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>注册页面</h1>
    <a href="login.html">跳转登录页面</a>
    <form action="">
        <input type="user" placeholder="用户名" name="" id="">
        <input type="password" placeholder="密码">
        <input type="submit" value="注册">
    </form>
    <script>
        
        var inps = document.querySelectorAll("input")
        document.forms[0].onsubmit = function (e) {
            e.preventDefault();
            var xhr = new XMLHttpRequest();
            xhr.open("post", "/zhuce");
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");


            var u = inps[0].value;
            var p = inps[1].value;

            
            xhr.send(`username=${u}&password=${p}`);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    console.log(xhr.responseText);
                    var res = JSON.parse(xhr.responseText);
                    console.log(res);
                }
            }
        }
    </script>
</body>

</html>